# -*- coding = utf-8 -*-
# @Time : 2024/6/9 17:49
# @Author : 0505200213石浪
# @File : home.py
# @Software : PyCharm


from flask import render_template
from . import bp
import utils


# 首页
@bp.route('/')
def hello_world():
    utils.getHomeData()
    print(utils.homeData)
    return render_template("index.html", homeData=utils.homeData)


@bp.route('/index')
def index():
    return hello_world()


# 数据页面
@bp.route('/data/<username>')
def data(username):
    dataGrade = []
    dataNum = []
    sql = "select grade,count(grade) from movieFriends.movies group by grade"
    data2 = utils.db.execute(sql)
    for i in data2:
        dataGrade.append(str(i[0]) + "分")
        dataNum.append(i[1])
    return render_template("datatable.html", dataGrade=dataGrade, dataNum=dataNum, username=username)


# 关于页面
@bp.route('/about/<username>')
def about(username):
    return render_template("abouts.html", username=username)


# 首页
@bp.route('/home/<username>')
def home_page(username):
    utils.getHomeData()
    print(utils.homeData)
    return render_template("home.html", username=username, homeData=utils.homeData)
